VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "CWinHelp"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

' Commands to pass WinHelp()
Const HELP_CONTEXT = &H1         'Display topic in ulTopic
Const HELP_QUIT = &H2            'Terminate help
Const HELP_FINDER = &HB          'Display Contents tab
Const HELP_INDEX = &H3           'Display index
Const HELP_HELPONHELP = &H4      'Display help on using help
Const HELP_SETINDEX = &H5        'Set the current Index for multi index help
Const HELP_KEY = &H101           'Display topic for keyword in offabData
Const HELP_MULTIKEY = &H201
Const HELP_CONTENTS = &H3        'Display Help for a particular topic
Const HELP_SETCONTENTS = &H5     'Display Help contents topic
Const HELP_CONTEXTPOPUP = &H8    'Display Help topic in popup window
Const HELP_FORCEFILE = &H9       'Ensure correct Help file is displayed
Const HELP_COMMAND = &H102       'Execute Help macro
Const HELP_PARTIALKEY = &H105    'Display topic found in keyword list
Const HELP_SETWINPOS = &H203     'Display and position Help window

Const HH_DISPLAY_TOPIC = &H0
Const HH_SET_WIN_TYPE = &H4
Const HH_GET_WIN_TYPE = &H5
Const HH_GET_WIN_HANDLE = &H6
Const HH_DISPLAY_TEXT_POPUP = &HE   ' Display string resource ID or
                                        ' text in a pop-up window.
Const HH_HELP_CONTEXT = &HF         ' Display mapped numeric value in
                                          ' dwData.
Const HH_TP_HELP_CONTEXTMENU = &H10 ' Text pop-up help, similar to
                                      ' WinHelp's HELP_CONTEXTMENU.
Const HH_TP_HELP_WM_HELP = &H11     ' text pop-up help, similar to
                                          ' WinHelp's HELP_WM_HELP.



Private Type HELPWININFO
    wStructSize As Long
    x As Long
    y As Long
    dx As Long
    dy As Long
    wMax As Long
    rgChMember As String * 2
End Type

Private Declare Function WinHelp Lib "User32.dll" Alias "WinHelpA" (ByVal hwnd As Long, ByVal lpHelpFile As String, ByVal wCommand As Long, ByVal dwData As Any) As Long
Private Declare Function WinHelpByInfo Lib "User32.dll" Alias "WinHelpA" (ByVal hwnd As Long, ByVal lpHelpFile As String, ByVal wCommand As Long, dwData As HELPWININFO) As Long
Private Declare Function WinHelpByStr Lib "User32.dll" Alias "WinHelpA" (ByVal hwnd As Long, ByVal lpHelpFile As String, ByVal wCommand As Long, ByVal dwData$) As Long
Private Declare Function WinHelpByNum Lib "User32.dll" Alias "WinHelpA" (ByVal hwnd As Long, ByVal lpHelpFile As String, ByVal wCommand As Long, ByVal dwData&) As Long
Private Declare Function HtmlHelp Lib "hhctrl.ocx" Alias "HtmlHelpA" _
         (ByVal hwndCaller As Long, ByVal pszFile As String, _
         ByVal uCommand As Long, ByVal dwData As Long) As Long

Dim m_hWndMainWindow As Long        'hWnd to tell WINHELP the helpfile owner
Dim MainWindowInfo As HELPWININFO
Dim m_HelpFile As String

Public Property Let hwnd(ByVal m_hwnd As Long)
    m_hWndMainWindow = m_hwnd
End Property

Public Property Let HelpFile(ByVal m_hfile As String)
    m_HelpFile = m_hfile
End Property

Private Sub Class_Initialize()
    With MainWindowInfo
        .wStructSize = 26
        .x = 256
        .y = 256
        .dx = 512
        .dy = 512
        .rgChMember = Chr$(0) + Chr$(0)
    End With
    HelpFile = App.HelpFile
End Sub

Private Sub Class_Terminate()
    Call WinHelp(m_hWndMainWindow, m_HelpFile, HELP_QUIT, Chr$(0) + Chr$(0) + Chr$(0) + Chr$(0))
End Sub

Public Function ShowTopic(ByVal ContextID As Long) As Boolean
    ShowTopic = WinHelpByNum(m_hWndMainWindow, m_HelpFile, HELP_CONTEXT, CLng(ContextID))
End Function

Public Function ShowTopic2(ByVal ContextID As Long) As Boolean
    '=====================================================================
    '  DISPLAY CONTEXT SENSITIVE HELP IN WINDOW 2 ...
    '=====================================================================
    ShowTopic2 = WinHelpByNum(m_hWndMainWindow, m_HelpFile & ">HlpWnd02", HELP_CONTEXT, CLng(ContextID))
End Function

Public Function ShowTopic3(ByVal ContextID As Long) As Boolean
    '=====================================================================
    '  DISPLAY CONTEXT SENSITIVE HELP IN WINDOW 3 ...
    '=====================================================================
    ShowTopic3 = WinHelpByNum(m_hWndMainWindow, m_HelpFile & ">HlpWnd03", HELP_CONTEXT, CLng(ContextID))
End Function

Public Function ShowGlossary() As Boolean
    ShowGlossary = WinHelpByNum(m_hWndMainWindow, m_HelpFile, HELP_CONTEXT, CLng(64000))
End Function

Public Function ShowPopup(ByVal ContextID As Long) As Boolean
    ShowPopup = WinHelpByNum(m_hWndMainWindow, m_HelpFile, HELP_CONTEXTPOPUP, CLng(ContextID))
End Function

Public Function RunMacro(ByVal MacroString As String) As Boolean
    RunMacro = WinHelpByStr(m_hWndMainWindow, m_HelpFile, HELP_COMMAND, ByVal (MacroString))
End Function

Public Function ShowContents(ByVal ContextID As Long) As Boolean
     ShowContents = HtmlHelp(m_hWndMainWindow, m_HelpFile, HH_HELP_CONTEXT, CLng(ContextID))

    'ShowContents = WinHelpByNum(m_hWndMainWindow, m_HelpFile, HELP_CONTENTS, CLng(0))
End Function

Public Function ShowContentsTab() As Boolean
    ShowContentsTab = WinHelpByNum(m_hWndMainWindow, m_HelpFile, HELP_FINDER, CLng(0))
End Function

Public Function ShowHelpOnHelp() As Boolean
    ShowHelpOnHelp = WinHelpByNum(m_hWndMainWindow, m_HelpFile, HELP_HELPONHELP, CLng(0))
End Function

Public Function SearchHelp() As Boolean
    SearchHelp = WinHelp(m_hWndMainWindow, m_HelpFile, HELP_PARTIALKEY, ByVal "")
End Function

Public Function SearchHelpKeyWord(Argument As String) As Boolean
    SearchHelpKeyWord = WinHelp(m_hWndMainWindow, m_HelpFile, HELP_PARTIALKEY, ByVal Trim$(Argument))
End Function

Public Function SetHelpWindowSize(x As Integer, y As Integer, wx As Integer, wy As Integer) As Boolean
    '=====================================================================
    '  TO SET THE SIZE AND POSITION OF THE MAIN HELP WINDOW...
    '=====================================================================
    '     o   Call HelpWindowSize(x, y, dx, dy), where:
    '             x = 1-1024 (position from left edge of screen)
    '             y = 1-1024 (position from top of screen)
    '             dx= 1-1024 (width)
    '             dy= 1-1024 (height)
    '
    MainWindowInfo.x = x
    MainWindowInfo.y = y
    MainWindowInfo.dx = wx
    MainWindowInfo.dy = wy
    SetHelpWindowSize = WinHelpByInfo(m_hWndMainWindow, m_HelpFile, HELP_SETWINPOS, MainWindowInfo)
End Function

